<?php
/***************************************************************
*  Copyright notice
*  (c) 2009, jianyuzhu@gmail.com
*  All rights reserved
*  This script is part of the PPEMI project.
***************************************************************/

//
function func_price_format($value, $precision = 2) {
	if( strpos($value, '.') !== false ) {
		$value = substr($value, 0, strpos($value, '.') + 1 + $precision + 1);
		if( strlen($value) > $precision ) {
			if( substr($value, -1) >= 5 ) {
				if( $precision > 1 ) {
					$value = substr($value, 0, -1) + ('0.' . str_repeat(0, $precision-1) . '1');
				} elseif( $precision == 1 ) {
					$value = substr($value, 0, -1) + 0.1;
				} else {
					$value = substr($value, 0, -1) + 1;
				}
			} else {
				$value = substr($value, 0, -1);
			}
		}
	}
	
	return $value;
}

function func_price_discount($price, $discount) {
	if( $discount > 0 && $discount < 100 ) {
		return ($price/100 * (100 - $discount));
	} else {
		return $price;
	}
}
//
?>